<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<h1>二手车管理系统</h1>

<form th:action="@{/list}" method="get">
    车名：<input type="text" name="carName">

    车辆：<select name="carType">
    <option value="">全部</option>
    <span th:each="cartypes : ${cartypes}">
                <option th:text="${cartypes.name}" th:value="${cartypes.tid}"></option>
            </span>
</select>

    <input type="submit" value="查询"/>
    <input type="button" th:onclick="'location.href=\'/toAdd\''" value="新增二手车辆信息" />

</form>


<table border="1">
    <tr>
        <td>车名</td>
        <td>车价（元）</td>
        <td>里程</td>
        <td>购车时间</td>
        <td>车型</td>
        <td>车辆状态</td>
        <td>操作</td>
    </tr>
        <tr th:each=" car : ${list}">
            <td>[[${car.carName}]]</td>
            <td>[[${car.carPrice}]]</td>
            <td>[[${car.carMileage}]]</td>
            <td th:text="${#dates.format(car.carBuyTime,'yyyy-MM-dd')}"></td>
            <td>
                <span th:if="${car.carType==1}">轿车</span>
                <span th:if="${car.carType==2}">SUV</span>
                <span th:if="${car.carType==3}">MPV</span>
                <span th:if="${car.carType==4}">跑车</span>
                <span th:if="${car.carType==5}">皮卡</span>
            </td>
            <td>
                [[${car.carStatus==0?"在售":"已售"}]]
            </td>
            <td>
                <a href="javascript:void(0)" th:onclick="'location.href=\'/selectById?id='+${car.carId}+'\''">修改</a>
                <a href="javascript:void(0)" th:onclick="'del('+${car.carId}+')'">删除</a>
            </td>
        </tr>
    </c:forEach>
</table>

<p style="margin-left: 50px">
    共 [[${totalCount}]] 条记录
    <a th:href="@{/list(pageNo=1)}">首页</a>
    <a th:href="@{/list(pageNo=${pageNo -1})}" th:if="${pageNo > 1}">上一页</a>
    <span th:if="${pageNo == 1}">上一页</span>
    <a th:href="@{/list(pageNo=${pageNo+1})}" th:if="${pageNo < totalPages}">下一页</a>
    <span th:if="${pageNo == totalPages}">下一页</span>
    <a th:href="@{/list(pageNo=${totalPages})}">尾页</a>
    当前第 [[${pageNo}]] 页，总 [[${totalPages}]] 页
</p>

</body>
<script src="/js/jquery.js"></script>
<script>
    $(function () {
        $("tr:odd").css("background-color", "#fff")
        $("tr:even").css("background-color", "aquamarine")
        $("tr:eq(0)").css("background-color", "aqua")
    })

    function del(id) {
        if (confirm("确定要删除吗？")) {
            $.post('delete', {id: id}, function (data) {
                console.log(data)
                if (data) {
                    alert("删除成功！");
                    location.href = 'list';
                } else {
                    alert("删除失败！");
                    location.reload();
                }
            })
        }
    }
</script>
</html>